package com.compomics.prioritizer.db.accessors;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 * Created by IntelliJ IDEA.
 * User: niels
 * Date: 28/07/11
 * Time: 11:05
 * To change this template use File | Settings | File Templates.
 */
public class ProjectType extends Project_typeTableAccessor {

    public ProjectType(ResultSet rs) throws SQLException {
        super(rs);
    }

    /**
     * This methods reads all project_types from the Project_type table.
     *
     * @param aConn Connection to read the instruments from.
     * @return  ProjectType[] with the project types in the 'Project_type' table.
     * @throws java.sql.SQLException when the retrieving of the project_types went wrong.
     */
    public static ProjectType[] getAllProjectTypes(Connection aConn) throws SQLException {
        PreparedStatement prep = aConn.prepareStatement("select * from project_type");
        ResultSet rs = prep.executeQuery();
        Vector v = new Vector();
        while(rs.next()) {
            v.add(new ProjectType(rs));
        }
        rs.close();
        prep.close();
        ProjectType[] projectTypes = new ProjectType[v.size()];
        v.toArray(projectTypes);

        return projectTypes;
    }

    /**
     * Returns a String representation for this ProjectType.
     *
     * @return  String  with the String representation for this ProjectType.
     */
    public String toString() {
        return this.iName;
    }

}
